package com.example.administrator.exkotlin.ui.fragment.news

import android.content.Context
import android.content.Intent
import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import com.example.administrator.exkotlin.R

/**
 * 内容
 * */
class NewsContentActivity : AppCompatActivity() {

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_news_content)

        loadDatas()
    }

    private fun loadDatas() {
        val title = intent.getStringExtra("news_title")
        val content = intent.getStringExtra("news_content")
        if (title != null && content != null) {
            val fragment = fragmentManager.findFragmentById(R.id.fm_news) as NewsContentFragment
            fragment.loadNews(News(title, content))
        }
    }

    companion object {
        fun startNewsContentActivity(context: Context,news: News) {
            Intent(context, NewsContentActivity::class.java).run {
                putExtra("news_title", news.titel)
                putExtra("news_content", news.content)
                context.startActivity(this)
            }
        }
    }

}
